package com.example.tool.activtiy;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.RemoteViews;

import com.example.tool.R;
import com.example.tool.activtiy.base.BaseActivity;
import com.example.tool.mvp.CommonPresent;
import com.example.tool.util.DebugLog;

import butterknife.BindView;

/**
 * Created Date 2019/8/27
 *
 * @author liangkun
 * description：
 */
public class NotificationActivity extends BaseActivity<CommonPresent> {
    @BindView(R.id.card_home_one)
    protected CardView button;
    @BindView(R.id.card_home_item)
    protected CardView btnTwo;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_notificationn;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String id = "my_channel_01";
                String name = "我是渠道名字";
                NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                Notification notification = null;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
                    DebugLog.d("NotificationActivity 大于8.0");
                    notificationManager.createNotificationChannel(mChannel);
                    notification = new Notification.Builder(NotificationActivity.this)
                            .setChannelId(id)
                            .setContentTitle("5 new messages")
                            .setContentText("hahaha")
                            .setSmallIcon(R.mipmap.hsc_icon).build();
                } else {
                    DebugLog.d("NotificationActivity 小于8.0");
                    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(NotificationActivity.this)
                            .setContentTitle("5 new messages")
                            .setContentText("hahaha")
                            .setSmallIcon(R.mipmap.hsc_icon)
                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.hsc_icon))
                            .setOngoing(true);
                    notification = notificationBuilder.build();
                }
                notificationManager.notify(1, notification);

            }
        });
        btnTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                RemoteViews views = new RemoteViews(getPackageName(), R.layout.notify_custom);
                String id = "my_channel_01";
                String name = "我是渠道名字";
                NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                Notification notification = null;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
                    DebugLog.d("NotificationActivity 大于8.0");
                    views.setImageViewResource(R.id.iv,R.mipmap.dili04);
                    views.setTextViewText(R.id.tv,"hahahahahahah");
                    notificationManager.createNotificationChannel(mChannel);
                    notification = new Notification.Builder(NotificationActivity.this)
                            .setChannelId(id)
                            .setSmallIcon(R.mipmap.dili04)
                            .setCustomContentView(views).setAutoCancel(true).build();

                } else {
                    DebugLog.d("NotificationActivity 小于8.0");
                    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(NotificationActivity.this)
                            .setContentTitle("5 new messages")
                            .setContentText("hahaha")
                            .setSmallIcon(R.mipmap.hsc_icon)
                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.hsc_icon))
                            .setOngoing(true); //是否点击通知自动取消
                    notification = notificationBuilder.build();
                }
                notificationManager.notify(1, notification);


            }
        });
    }

    @Override
    protected CommonPresent createPresenter() {
        return null;
    }
}
